﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SDM.ExamPlanner.DALC;
using SDM.ExamPlanner.DTO;

namespace SDM.ExamPlanner.Test
{
    [TestClass]
    public class TeacherTest : BaseTest
    {
        [TestMethod]
        public void AddTeacherTest()
        {
            // Assign
            var teacherRepository = new DataRepository<Teacher>();

            // Act
            teacherRepository.RegisterNew(TestObjects.TeacherObject1());
            teacherRepository.SaveChanges();
            var teacher = teacherRepository.Find();

            // Assert
            Assert.AreEqual(1, teacher.Count());
        }

        [TestMethod]
        public void GetAllTeachersTest()
        {
            // Assign
            var teacherRepository = new DataRepository<Teacher>();

            // Act
            teacherRepository.RegisterNew(TestObjects.TeacherObject1());
            teacherRepository.RegisterNew(TestObjects.TeacherObject2());
            teacherRepository.SaveChanges();
            var teacher = teacherRepository.Find();

            // Assert
            Assert.AreEqual(2, teacher.Count());
        }

        [TestMethod]
        public void ShowAllTeachersOfClassTest()
        {
            // Assign
            var schoolClassRepository = new DataRepository<SchoolClass>();
            String className = TestObjects.SchoolClassObject1().Name;
            var schoolClass = new SchoolClass();

            // Act
            schoolClassRepository.RegisterNew(TestObjects.SchoolClassObject1());
            schoolClassRepository.SaveChanges();

            var schoolClasses = schoolClassRepository.Find().Where(e => e.Name == className);
            
            schoolClass = schoolClasses.First();

            // Assert
            Assert.AreEqual(2, schoolClass.Teachers.Count);

            int count = 1;
            foreach (var teacher in schoolClass.Teachers)
            {
                if (count == 1)
                    Assert.AreEqual(TestObjects.TeacherObject1().Cpr, teacher.Cpr);
                else
                    Assert.AreEqual(TestObjects.TeacherObject2().Cpr, teacher.Cpr);
                count++;
            }
        }
    }
}
